<template>
	<view class="teaching-assistant-manage">
		<view class="assistant-table" v-if="list.length>0">
			<view class="table-item table-head">
				<view class="name">花名</view>
				<view class="sex">性别</view>
				<view class="type">桌台类型</view>
				<view class="status">状态</view>
				<view class="operate">操作</view>
			</view>
			<view class="table-item" v-for="item in list" :key="item.id">
				<view class="name">{{item.nickName}}</view>
				<view class="sex">{{formatGender(item.gender)}}</view>
				<view class="type">{{formatTableType(item.tableType)}}</view>
				<view class="status" :style="{color:item.auditStatus==3?'#d12920':''}">{{formatStatus(item.auditStatus)}}</view>
				<view class="operate">
					<text @tap="handleEdit(item)">编辑</text>
					<text v-if="item.auditStatus==2" style="color: #d12920;" @tap="forbid(item.id)">禁用</text>
					<text v-if="item.auditStatus==4" @tap="enable(item.id)">启用</text>
				</view>
			</view>
		</view>
		<view class="quesheng flexWarpCenterColumn" v-else>
			<image src="https://static.mo-yu.vip/wechat/images/orderEmpty.png"></image>
			<view class="text">还没有助教数据哦，请先去添加吧~</view>
		</view>
		<view class="bottom-btn">
			<view class="btn" @tap="goPage('/moduleB/manage/addAndEditTeachingAssistant')">新增</view>
		</view>
		
		<!--操作指引悬浮按钮 -->
		<guideline :path="'moduleB/manage/teachingAssistantManage'"></guideline>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				list:[],
				tableType:[
					{label:'麻将包房',value:0},
					{label:'中式黑八',value:1},
					{label:'美式九球',value:2},
					{label:'斯诺克',value:3},
					{label:'棋牌',value:4},
				]
			}
		},
		onShow() {
			this.getList()
		},
		methods:{
			// 获取助教列表
			getList(){
				this.$request.get(this.$api.assistantList, {
					storeId:uni.getStorageSync('store_id'),
					isJava:true,
				}).then(res => {
					let {
						data = {}
					} = res;
					this.list=data||[]
				})
			},
			
			formatGender(value){
				switch(value){
					case 0:
						return '女';
					case 1:
						return '男';
					default:
						return '其他'
				}
			},
			
			formatTableType(value){
				let tableValue=''
				let tempValue=value.split(',')
				let choose=this.getAbsentValues(this.tableType,tempValue)
				let temp = []
				choose.forEach(item=>{
					temp.push(item.label)
				})
				return temp.toString()	
			},
			
			// 过滤出选中的数据
			getAbsentValues(arr1, arr2){
			    let res = [];
			    res = arr1.filter(item => {
			        return arr2.find(el => {
			            return item.value == el
			       });
			    });
			    return res
			},
			
			formatStatus(value){
				switch(value){
					case 1:
						return '待审核';
					case 2:
						return '正常';
					case 3:
						return '审核未通过';
					case 4:
						return '禁用';
					default:
						return ''
				}
			},
			
			// 编辑
			handleEdit(item){
				if(item.auditStatus==4){
					this.$tools.showToast('助教已禁用，不可修改')
				}else{
					uni.navigateTo({
						url:'/moduleB/manage/addAndEditTeachingAssistant?id='+item.id
					})
				}
			},
			
			// 禁用
			forbid(id){
				uni.showModal({
					title: '确定禁用助教？',
					content: '禁用后不影响进行中的助教订单',
					confirmText:'确定禁用',
					confirmColor:'#45B250',
					success: res=> {
						if (res.confirm) {
							this.$request.get(this.$api.assistantForbid, {
								id:id,
								isJava:true,
							}).then(res => {
								if(res.code==200){
									this.$tools.showToast('禁用成功')
									this.getList()
								}
							})
						} 
					}
				})
			},
			
			// 启用
			enable(id){
				this.$request.get(this.$api.assistantEnable, {
					id:id,
					isJava:true,
				}).then(res => {
					if(res.code==200){
						this.$tools.showToast('启用成功')
						this.getList()
					}
				})		
			},	
		},
	}
</script>

<style lang="scss" scoped>
	.teaching-assistant-manage{
		padding: 32rpx;
	}
	.assistant-table{
		background: #1D1C5C;
		overflow: hidden;
		margin-bottom: 50rpx;
		border-radius: 10rpx;
		padding: 30rpx;
		.table-item{
			display: flex;
			color: #fff;
			font-size: 24rpx;
			text-align: center;
			border-bottom:1rpx solid  #36355E;
			&:first-child{
				border-top:1rpx solid  #36355E;
			}
			>view{
				padding: 16rpx 10rpx;
				box-sizing: border-box;
				display: flex;
				justify-content: center;
				align-items: center;
			}
			.name{
				width: 130rpx;
				border-left:2rpx solid #36355E;
				border-right:2rpx solid #36355E;
			}
			.sex{
				width: 90rpx;
				border-right:2rpx solid #36355E;
			}
			.type{
				flex:1;
				// width: 180rpx;
				border-right:2rpx solid #36355E;
			}
			.status{
				width: 100rpx;
				border-right:2rpx solid #36355E;
			}
			.operate{
				width: 140rpx;
				font-size: 24rpx;
				gap:20rpx;
				color: #26BCFD;
				border-right:2rpx solid #36355E;
			}
		}
		.table-head{
			>view{
				font-weight: bold;
				font-size: 28rpx !important;
				color: #26BCFD;
			}
		}
	}
	
	.quesheng{
		image{
			width: 476upx;
			height: 280upx;
		}
		.text{
			color: #fff;
			font-size: 36rpx;
			margin: 50rpx 0 200rpx 0;
			text-align: center;
		}
	}
	
	.bottom-btn{
		width: 100%;
		position: sticky;
		bottom: 50rpx;
		left: 0;
		.btn{
			width: 670rpx;
			height: 80rpx;
			margin: 0 auto;
			background: rgb(31, 124, 247);
			border-radius: 72rpx;
			font-size: 34rpx;
			color: #fff;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}
</style>